import request from '@/utils/request'

/**
 * 获取所有权限
 * @returns promise
 */
export const getPermissionList = () => {
  return request({
    url: '/sys/permission',
    method: 'GET'
  })
}

/**
 * 添加权限
 * @param {*} data {}
 * @returns promise
 */
export const updatePermissionList = (data) => {
  return request({
    url: '/sys/permission',
    method: 'POST',
    data
  })
}

/**
 * 根据id获取用户权限详情
 * @param {*} id
 * @returns promise
 */
export const getPermissionInfo = (id) => {
  return request({
    url: '/sys/permission/' + id,
    method: 'GET'
  })
}

/**
 * 更新用户权限
 * @param {*} data {}
 * @returns promise
 */
export const updatePermissionInfo = (data) => {
  return request({
    url: '/sys/permission/' + data.id,
    method: 'PUT',
    data
  })
}

/**
 * 根据id删除权限
 * @param {*} id
 * @returns promise
 */
export const delPermission = (id) => {
  return request({
    url: '/sys/permission/' + id,
    method: 'DELETE'
  })
}

/**
 * 给角色分配权限
 * @param {*} data 对象：角色id，权限id的集合
 * @returns promise
 */
export const setPermissionToRole = (data) => {
  return request({
    url: '/sys/role/assignPrem',
    method: 'PUT',
    data
  })
}
